package com.zggk.lzz.lzmlbj;

import android.app.Activity;
import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.callback.StringDialogCallback;
import com.zggk.lzz.lzml.Lzml2Bean;
import com.zggk.lzz.lzml.LzmlBean;
import com.zggk.lzz.mvp.BasePresenterImpl;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class LzmlBjPresenter extends BasePresenterImpl<LzmlBjContract.View> implements LzmlBjContract.Presenter{
    @Override
    public void getData(String js, String xj, String xxj, String cj, Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/rhms/lzzapp/getUserByScreen")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .params("shi", js)
                .params("xian", xj)
                .params("xiang", xxj)
                .params("cun", cj)
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LzmlBean lzmlBean = JSON.parseObject(response.body(),LzmlBean.class);
                        if (mView == null)
                            return;
                        if (lzmlBean.getCode().equals("200")){
                            mView.getDatas(lzmlBean.getData());
                        }else {
                            mView.onRequestError(lzmlBean.getMessage());
                        }
                    }
                });
    }

    @Override
    public void getSData(String js,String xj,String xxj,String cj) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/rhms/lzzapp/getZQ")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .params("shi", js)
                .params("xian", xj)
                .params("xiang", xxj)
                .params("cun", cj)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Lzml2Bean lzml2Bean = JSON.parseObject(response.body(),Lzml2Bean.class);
                        if (mView == null)
                            return;
                        if (lzml2Bean.getCode().equals("200")){
                            mView.getSDatas(lzml2Bean.getData());
                        }else {
                            mView.onRequestError(lzml2Bean.getMessage());
                        }
                    }
                });
    }

    @Override
    public void delete(String ids, Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/lzz/roadModelMessage/roadModelAdministrator/delete")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .params("ids", ids)
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        DeleteBean deleteBean = JSON.parseObject(response.body(),DeleteBean.class);
                        if (mView == null)
                            return;
                        if (deleteBean.getType()==200){
                            mView.deletes();
                        }else {
                            mView.onRequestError(deleteBean.getMsg());
                        }
                    }
                });
    }
}
